package Controllers;

import java.rmi.RemoteException;
import Common.*;
import listeners.CanPieceMoveListener;

import Models.ChessPieceModel;
import Models.StandardChessPieceModel;
import Models.Point2D;


public class PawnController implements ChessPieceControllerInterface, CanPieceMoveListener {

	
	
	public PawnController () {
		
		
	}
	@Override
	public boolean legalMove(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		if (moveVector.getX()==0 && moveVector.getY() == 1) {
			chessPiece.setMove(true);
			return true;
			
		}
		else if (!chessPiece.getMove() && (moveVector.getX() == 0) && (moveVector.getY() == 2)) {
			chessPiece.setMove(true);
			return true;
		}
		
		else {
		
		return false;
		}
		
	}

	
	@Override
	public boolean legalCapture(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		if (moveVector.getX() == 1 && moveVector.getY() ==1) {
			return true;
		}
		
		else if (moveVector.getX() == -1 && moveVector.getY() ==1) {
			return true;
		}
		
		else {
			return false;
		}
	}
	
	
	
	@Override
	public boolean canPieceMoveNotify(Point2D from, Point2D to,
			ChessPieceModel chessPiece) throws RemoteException {
		
		return legalMove(Helper.calculateVector(from, to), chessPiece);
	}
	
	
	public static ChessPieceModel getNew() throws RemoteException {
		ChessPieceModel pawn = new StandardChessPieceModel();
		ChessPieceControllerInterface pawnController = new PawnController();
		pawn.addCanPieceMoveListener(pawnController);
		return pawn;
	}

}
